﻿<UserControl x:Class="ViewMaker.Core.Views.ViewLayoutView"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:system="clr-namespace:System;assembly=mscorlib" >
    <UserControl.Resources>
        <ContextMenu x:Key="treeViewItemMenu">
            <MenuItem Header="Move">
                <MenuItem Command="{Binding Path=Owner.UpCommand}">
                    <MenuItem.Header>
                        <StackPanel Orientation="Horizontal">
                            <Image Source="/ViewMaker.Core;component/Images/up.png" Height="16" Width="16" />
                            <TextBlock>Up</TextBlock>
                        </StackPanel>
                    </MenuItem.Header>
                </MenuItem>
                <MenuItem Command="{Binding Path=Owner.DownCommand}">
                    <MenuItem.Header>
                        <StackPanel Orientation="Horizontal">
                            <Image Source="/ViewMaker.Core;component/Images/down.png" Height="16" Width="16" />
                            <TextBlock>Down</TextBlock>
                        </StackPanel>
                    </MenuItem.Header>
                </MenuItem>
                <MenuItem Command="{Binding Path=Owner.LeftCommand}">
                    <MenuItem.Header>
                        <StackPanel Orientation="Horizontal">
                            <Image Source="/ViewMaker.Core;component/Images/left.png" Height="16" Width="16" />
                            <TextBlock>Left</TextBlock>
                        </StackPanel>
                    </MenuItem.Header>
                </MenuItem>
                <MenuItem Command="{Binding Path=Owner.RightCommand}">
                    <MenuItem.Header>
                        <StackPanel Orientation="Horizontal">
                            <Image Source="/ViewMaker.Core;component/Images/right.png" Height="16" Width="16" />
                            <TextBlock>Right</TextBlock>
                        </StackPanel>
                    </MenuItem.Header>
                </MenuItem>
            </MenuItem>
            <MenuItem Header="Change Control" ItemsSource="{Binding Path=SelectableTypeList}" >
                <MenuItem.ItemContainerStyle>
                    <Style TargetType="{x:Type MenuItem}">
                        <Setter Property="CommandParameter" Value="{Binding}"/>
                        <EventSetter Event="Click" Handler="MenuItemModify_Click" />
                    </Style>
                </MenuItem.ItemContainerStyle>
            </MenuItem>
            <MenuItem Header="Add Item" ItemsSource="{Binding Path=AddItemList}" >
                <MenuItem.ItemContainerStyle>
                    <Style TargetType="{x:Type MenuItem}">
                        <Setter Property="CommandParameter" Value="{Binding}"/>
                        <EventSetter Event="Click" Handler="MenuItemAddItem_Click" />
                    </Style>
                </MenuItem.ItemContainerStyle>
            </MenuItem>
            <MenuItem Header="Add Control" ItemsSource="{Binding Path=AddControlList}" >
                <MenuItem.ItemContainerStyle>
                    <Style TargetType="{x:Type MenuItem}">
                        <Setter Property="CommandParameter" Value="{Binding}"/>
                        <EventSetter Event="Click" Handler="MenuItemAddControl_Click" />
                    </Style>
                </MenuItem.ItemContainerStyle>
            </MenuItem>
            <MenuItem Header="Remove" Command="{Binding Path=Owner.RemoveItemCommand}" />
            <MenuItem Header="Insert Panel" Command="{Binding Path=Owner.InsertControlCommand}" />
            <MenuItem Header="Show XAML" Command="{Binding Path=Owner.ShowCurrentXamlCommand}" />
        </ContextMenu>
    </UserControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="auto" />
            <RowDefinition Height="240" />
            <RowDefinition  />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
        </Grid.ColumnDefinitions>
        <Menu FocusManager.IsFocusScope="False">
            <MenuItem Header="File">
                <MenuItem Header="Show XAML" Command="{Binding Path=ShowXamlCommand}"  />
                <MenuItem Header="Show Layout" Command="{Binding Path=ShowLayoutViewerCommand}" />
                <MenuItem Header="Close" Command="{Binding Path=CloseCommand}" />
            </MenuItem>
 
            <!--<MenuItem Header="Edit">
                <MenuItem Header="Move Up" Command="{Binding Path=UpCommand}" />
                <MenuItem Header="Move Down" Command="{Binding Path=DownCommand}" />
                <MenuItem Header="Move Left" Command="{Binding Path=LeftCommand}" />
                <MenuItem Header="Move Right" Command="{Binding Path=RightCommand}" />
                <Separator />
                <MenuItem Header="Remove" Command="{Binding Path=RemoveItemCommand}" />
            </MenuItem>-->
            <MenuItem  Command="{Binding Path=RefreshCommad}">
                <MenuItem.Header>
                    <Image Source="/ViewMaker.Core;component/Images/refresh.png" Height="20" Width="20" />
                </MenuItem.Header>
            </MenuItem>
            <MenuItem Command="{Binding Path=SaveLayoutCommand}">
                <MenuItem.Header>
                    <Image Source="/ViewMaker.Core;component/Images/save.png" Height="20" Width="20" />
                </MenuItem.Header>
            </MenuItem>
            <MenuItem Command="{Binding Path=EditViewControlSettingsCommand}">
                <MenuItem.Header>
                    <Image Source="/ViewMaker.Core;component/Images/settings.png" Height="20" Width="20" />
                </MenuItem.Header>
            </MenuItem>
            <MenuItem Command="{Binding Path=UpCommand}">
                <MenuItem.Header>
                    <Image Source="/ViewMaker.Core;component/Images/up.png" Height="20" Width="20" />
                </MenuItem.Header>
            </MenuItem>
            <MenuItem Command="{Binding Path=DownCommand}" >
                <MenuItem.Header>
                    <Image Source="/ViewMaker.Core;component/Images/down.png" Height="20" Width="20" />
                </MenuItem.Header>
            </MenuItem>
            <MenuItem Command="{Binding Path=LeftCommand}" >
                <MenuItem.Header>
                    <Image Source="/ViewMaker.Core;component/Images/left.png" Height="20" Width="20" />
                </MenuItem.Header>
            </MenuItem>
            <MenuItem Command="{Binding Path=RightCommand}" >
                <MenuItem.Header>
                    <Image Source="/ViewMaker.Core;component/Images/right.png" Height="20" Width="20" />
                </MenuItem.Header>
            </MenuItem>
            <MenuItem Command="{Binding Path=RemoveItemCommand}" >
                <MenuItem.Header>
                    <Image Source="/ViewMaker.Core;component/Images/remove.png" Height="20" Width="20" />
                </MenuItem.Header>
            </MenuItem>
        </Menu>
        <TreeView Grid.Row="1" x:Name="treeView" ItemsSource="{Binding Path=Root}" SelectedItemChanged="treeView_SelectedItemChanged" PreviewKeyDown="treeView_PreviewKeyDown">
            <TreeView.ItemContainerStyle>
                <Style TargetType="{x:Type TreeViewItem}">
                    <Setter Property="FontWeight" Value="Normal" />
                    <Setter Property="ContextMenu" Value="{StaticResource treeViewItemMenu}" />
                    <EventSetter Event="TreeViewItem.MouseRightButtonDown" Handler="TreeViewItem_MouseRightButtonDown"/>
                    <Style.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="FontWeight" Value="Bold" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </TreeView.ItemContainerStyle>

            <TreeView.ItemTemplate>
                <HierarchicalDataTemplate ItemsSource="{Binding Children}">
                    <TextBlock Text="{Binding Title}" />
                </HierarchicalDataTemplate>
            </TreeView.ItemTemplate>
        </TreeView>

        <ScrollViewer Grid.Column="0" Grid.Row="2">
            <StackPanel>
                <Expander IsExpanded="True" Header="Layout Item" >
                    <ContentControl  Name="propPanel" Content="{Binding Path=ItemContent, Mode=OneWay}" IsTabStop="False">
                    </ContentControl>
                </Expander>
                <Expander IsExpanded="True" Header="Layout Control">
                    <ContentControl  Name="editPanel" Content="{Binding Path=ControlContent, Mode=OneWay}" IsTabStop="False">
                    </ContentControl>
                </Expander>
            </StackPanel>

        </ScrollViewer>
        <StackPanel Grid.Column="0" Grid.Row="3" Margin="3">
            <TextBlock Name="cntlInfo" Height="20" Text="{Binding Path=InfoText}" ></TextBlock>
        </StackPanel>

        <GridSplitter Height="3" 
            HorizontalAlignment="Stretch" Grid.Row="1" VerticalAlignment="Bottom"/>
    </Grid>
</UserControl>
